<template>
    <div>
        <el-row class="head">
            <el-col :span="8">
                <div class="">{{company?company:this.$store.state.company}}</div>
                </el-col>
            <el-col :span="8">
                <h2>
                    工作人员管理平台
                </h2>
            </el-col>
            <el-col :span="8">
                <div>
                  
                </div>
            <div v-if="this.$store.state.name?this.$store.state.name:name" class="name-ico">
                <el-dropdown>
                    <span class="el-dropdown-link">
                    {{name?name:this.$store.state.name}}<i class="el-icon-caret-bottom el-icon--right"></i>
                    </span>
                    <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item ><span @click="Signout" class="spanbox">退出登录</span></el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
          </div>
               
            </el-col>
        </el-row> 
        <div class="rest-box">
            <h2>重置密码</h2>
           <el-form :model="ruleForm2" status-icon :rules="rules2" ref="ruleForm2" class="demo-ruleForm">
                <el-form-item prop="pass">
                    <el-input type="password" v-model="ruleForm2.pass" auto-complete="off" placeholder="请输入新密码"></el-input>
                </el-form-item>
                <el-form-item  prop="checkPass">
                    <el-input type="password" v-model="ruleForm2.checkPass" auto-complete="off" placeholder="确认新密码"></el-input>
                </el-form-item>
                
                <el-form-item>
                    <el-button style="width:100%" type="primary" @click="submitForm('ruleForm2')">确定</el-button>
                    
                </el-form-item>

                <el-form-item>
                    <router-link tag="div" to="/State" class="fanghu el-icon-caret-left">返回设置页</router-link>
                    
                </el-form-item>
            </el-form>
        </div>
        
    </div>
</template>

<script>
import moment from "moment/moment";
import {reset} from '../api/api'
export default {
  data() {
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else {
        if (this.ruleForm2.checkPass !== "") {
          this.$refs.ruleForm2.validateField("checkPass");
        }
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入密码"));
      } else if (value !== this.ruleForm2.pass) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };
    return {
      company: sessionStorage.getItem("company"),
      date: moment(new Date()).format("YYYY-MM-DD"),
      name: sessionStorage.getItem("name"),
      ruleForm2: {
        pass: "",
        checkPass: ""
      },
      rules2: {
        pass: [{ validator: validatePass, trigger: "blur" }],
        checkPass: [{ validator: validatePass2, trigger: "blur" }]
      }
    };
  },
      methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            var putdata = {
              password:this.ruleForm2.checkPass 
            }
            reset(putdata).then(res => {
              sessionStorage.removeItem('token')
              sessionStorage.removeItem('name')
              this.$router.push({path:'/login'})
            }).catch(err => {
               alert('修改失败');
            })
          } else {
            // console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
       //   退出
    Signout() {
      this.name = "";
      this.company = "";
      sessionStorage.removeItem("token");
      sessionStorage.removeItem("company");
      sessionStorage.removeItem("name");
      this.$router.push({ path: "/login" });
    }
    }
};
</script>

<style lang="scss" scoped>
body {
	margin: 0px;
	padding: 0px;
	/*background: url(assets/bg1.jpg) center !important;
		background-size: cover;*/
	// background: #1F2D3D;
	font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, SimSun, sans-serif;
	font-size: 14px;
	-webkit-font-smoothing: antialiased;
}
.head {
  height: 40px;
  text-align: center;
  line-height: 40px;
  color: #fff;
  background-color: #333333;
  position: relative;
  z-index: 88888;
  margin-bottom: 50px;
  h2 {
    margin: 0;
    padding: 0;
  }
  .name-ico {
    position: absolute;
    top: 0px;
    right: 30px;
    font-size: 30px;
    color: #fff;
    .el-dropdown {
      font-size: 14px;
      color: #fff;
    }
  }
}
.rest-box {
  width: 300px;
  height: 430px;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  h2{
      text-align: center;
      font-size: 24px;
      color: #363636;
      padding-bottom: 60px;
  }
}
.fanghu{
    color: #ccc;
    text-align: center;
    display: block;
}
</style>

